<template>
	<view>
		<view class="forget-bg">
			<view class="forget-card">
				<view class="forget-input forget-margin-b">
					<input type="text" placeholder="用户名" v-model="form.username"/>
				</view>
				<view class="forget-input forget-margin-b">
					<input type="text" placeholder="密码" v-model="form.password"/>
				</view>
				<view class="forget-input forget-margin-b">
					<input type="text" placeholder="昵称" v-model="form.nickname"/>
				</view>
				<view class="forget-input forget-margin-b">
					<input type="number" placeholder="手机号" v-model="form.mobile"/>
				</view>
				<view class="forget-input forget-margin-b">
					<input type="text" placeholder="Email" v-model="form.email"/>
				</view>
			</view>
			<view class="forget-btn">
				<button class="landing" type="primary" @click="submit">添加</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				form: {
					username: "",
					password: "",
					nickname: "",
					mobile: "",
					email: ""
				}
			}
		},
		onLoad(option) {
			console.log("编辑ID：" + option.id);
			this.getDataById(option.id);
		}
		methods: {
			getDataById(_id) {
				uniCloud.callFunction({
					name: "getUserById",
					data: {
						"id": _id
					},
					success: (e) => {
						console.log(e.result);
						this.usernaem = e.result.data[0].usernaem;
						this.password = e.result.data[0].password;
						this.email = e.result.data[0].email;
						this.mobile = e.result.data[0].mobile;
						this.nickname = e.result.data[0].nickname;
						this.id = e.result.data[0]._id;
					}
				})
			},
			editUser(){
				console.log("-------执行编辑操作"-------);
				uniCloud.callFunction({
					name: "editUser",
					data: {
						"id": this.id,
						"username": this.usernaem,
						"password": this.password,
						"email": this.email,
						"mobile": this.mobile,
						"nickname": this.nickname
					},
					success: (e) => {
						uni.showToast({
							title: '编辑成功',
							duration: 2000
						});
						uni.navigateTo({
							url: '../list/list',
						});
					}
				})
			}
		}
	}
</script>

<style>
</style>